import request from '@/utils/axios';
import { auth } from '@/config/env';

export const page = param => {
  return request({
    url: auth + '/function/page',
    method: 'post',
    data: param,
  });
};

export const functionDetail = id => {
  return request({
    url: auth + '/function/' + id + '/detail/tree',
    method: 'get',
  });
};

export const saveFunctionDetail = param => {
  return request({
    url: auth + '/function/' + param.id + '/detail',
    method: 'post',
    data: param.detail,
  });
};

export const saveDetail = model => {
  return request({
    url: auth + '/function/detail',
    method: 'post',
    data: model,
  });
};

export const find = param => {
  return request({
    url: auth + '/function/find',
    method: 'post',
    data: param,
  });
};

export const findById = id => {
  return request({
    url: auth + '/function/' + id,
    method: 'get',
  });
};

export const save = model => {
  return request({
    url: auth + '/function',
    method: 'post',
    data: model,
  });
};

export const edit = model => {
  return request({
    url: auth + '/function/' + model.id,
    method: 'put',
    data: model,
  });
};

export const isActive = model => {
  return request({
    url: auth + '/function/isActive/' + model.id,
    method: 'put',
    params: {
      status: model.status,
    },
  });
};

export const del = id => {
  return request({
    url: auth + '/function/' + id,
    method: 'delete',
  });
};

export const batchDel = ids => {
  return request({
    url: auth + '/function',
    method: 'delete',
    data: ids,
  });
};
